/*
 * @Author: lusx
 * @Date: 2019-02-18 13:40:50
 * @Last Modified by: lusx
 * @Last Modified time: 2019-02-21 17:59:39
 */

import {toJS} from 'mobx';
import { observable, action } from 'mobx';
import {message} from 'antd';
import * as  Apis from '../apis/govern';
import {ListStore} from './listStore';
import {WeaSelect,WeaLocaleProvider} from 'ecCom';

const getLabel = WeaLocaleProvider.getLabel;

export default class CountStore extends ListStore{
    @observable data = {};
    //@observable conditionNum = [];
    @observable loading = false;
    @observable searchsBaseValue = '';
    queryType = {"type":''};
    searchParam = {};
    @observable isContain = 0;
    constructor(props) {
      super(props);
      this.init = this.init.bind(this);
      //this.getSearchPanel = this.getSearchPanel.bind(this);
      this.doSearch = this.doSearch.bind(this);
    }
    /**
     *
     * @method count
     * @for InfoStore
     * @param {参数类型} {"type":String} 参数说明  页面请求的type参数值;
     * @return {返回值类型} {}
     */
    @action
    init(params){
      this.queryType = params;
      this.loading = true;
      Apis.getProjectCount(params).then(data=>{
        if(data.status ==1){
          data.sessionkey && this.tableStore.getDatas(data.sessionkey, 1 );
          data.config&&data.config.unshift({
            label: getLabel(514432 ,'是否包含事项'),
            labelcol: 3,
            fieldcol: 8,
            com:<WeaSelect ecId={`${this && this.props && this.props.ecId || ''}_WeaSelect@finrcn`} options={ [ {key: "1",showname: ""}]} detailtype={2} onChange={this.selctOnchange} />
          })
          this.data = data;
          this.searchsBaseValue = '';
          if(!data.config){
              this.isContain = 0;//xk:切换菜单时清空值 
          }
        }else{
          message.error(data.error);
        }
        this.loading = false;
      })
    }
    //初始化搜索面板
    // @action
    // getSearchPanel(params){
    //     Apis.getTaskListConditions({"isSuper":"1"}).then(data=>{
    //             if(parseInt(data.status) == 1){
    //               this.conditionNum= data.searchCondition;
    //               this.formB && !this.formB.isFormInit && this.formB.initFormFields(data.searchCondition);
    //             }else{
    //               message.error(data.error);
    //             }
    //      })
    // }
    //高级搜索方法
    @action
    doSearch(v){
      this.searchsBaseValue = v;
      // const formParams = this.formB.getFormParams(),
      //       datas = this.queryType,
      //       newParams = {...datas,"value":v};
      const datas = this.queryType,
            newParams = {...datas,"value":v};
      this.init(newParams);
    }

    @action
    searchByDate=(params)=>{
      this.searchParam = {...params};
      let newParams = {'type':'0',...params,isContain:this.isContain}
      this.init(newParams);
    }

    
    @action
    selctOnchange =(params) =>{
      this.isContain = params;
      let newParams = {isContain:params,...this.searchParam}
      this.searchByDate(newParams);
    }
}
